<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * CodeIgniter
 *
 * An open source application development framework for PHP 4.3.2 or newer
 *
 * @package		CodeIgniter
 * @author		ExpressionEngine Dev Team
 * @copyright	Copyright (c) 2008 - 2009, EllisLab, Inc.
 * @license		http://codeigniter.com/user_guide/license.html
 * @link		http://codeigniter.com
 * @since		Version 1.0
 * @filesource
 */
// ------------------------------------------------------------------------

/**
 * @package		CodeIgniter
 * @subpackage	Libraries
 * @author		AnhDT
 */
 
	class Fx_Mini_Block extends Fx_Block
	{
		protected $_header = '';
		protected $_showExpButton = true;
		protected $_maximumItems  = 'unlimited';
		protected $_items         = array();
		protected $_width         = '201px';
		
		function __construct() {
			parent::__construct();
			$this->__init();
		}
		
		function setHeader($_header = '') {
			if (!is_string($_header) || empty($_header)) {
				return false;
			}
			$this->_header = $_header;
			return $this;
		}
		
		function getHeader() {
			return $this->_header;	
		}
		
		function showExpButton($_show = true) {
			$this->_showExpButton = $_show;
			return $this;
		}
		
		function addItem($_item) {
			if (!is_object($_item)) {
				$_item = (object)$_item;
			}
			if (!isset($_item->id) || !isset($_item->label)) {
				return false;	
			}
			$this->_items[$_item->id] = $_item;
			return $this;
		}
		
		function removeItem($_item) {
			if (is_string($_item)) {
				if (isset($this->_items[$_item])) {
					unset($this->_items[$_item]);	
					return $this;
				}
				return false;
			}	
			if (!is_object($_item)) {
				$_item = (object)$_item;
				if (isset($_item->id)) {
					removeItem($_item->id);
					return $this;
				}
				return false;
			}
			return false;
		}
		
		function getItems() {
			return $this->_items;
		}
		
		function clearItems() {
			$this->_items = array();
			return $this;	
		}
		
		function getOutputHtml() {
			$output	= "\n<div class=\"blockMini block clear\">".
					  "<div class=\"blockHeader block clear\">\n".
					  "<div class=\"blockHeaderLeft left\">\n".
					  "<h4 class=\"headerTitle\">$this->_header</h4>\n".
					  "</div>\n".
					  "<div class=\"blockHeaderRight left\">\n".
					  "<a class=\"utilButton expButton\" id=\"expButton\" href=\"#\"></a>\n".
					  "</div>\n".
					  "</div>\n".
					  "<div class=\"blockContent block clear\">\n".
					  "<ul class=\"list noMargin noListStyle\">\n";
			foreach ($this->_items as $_id => $_item) {
				$output .= "<li id=\"$_id\"><a href=\"$_item->url\">$_item->label</a></li>\n";	
			} 	
			$output .= "</ul>\n".
					   "</div>\n".
					   "</div>\n";	
			return $output;
		}
		
		function toHtml() {
			echo $this->getOutputHtml();
			return $this;
		}
		
		protected function __init() {
			$this->setVisible(true);
			return $this;	
		}
	}
?>